package cn.hsw.manage.center.service.impl;

import cn.hsw.manage.center.entity.RolePermissionCenter;
import cn.hsw.manage.center.entity.UserRoleCenter;
import cn.hsw.manage.center.mapper.RolePermissionMapper;
import cn.hsw.manage.center.service.RolePermissionCenterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class RolePermissionCenterServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermissionCenter> implements RolePermissionCenterService {
    @Override
    @Transactional
    public void bind(Long rolePid, List<Long> permissionPidList) {
        baseMapper.deleteByRolePid(rolePid);

        List<RolePermissionCenter> insList = permissionPidList.stream().map(aLong -> RolePermissionCenter.builder()
                .rolePid(rolePid)
                .permissionPid(aLong).build()).collect(Collectors.toList());

        this.saveBatch(insList);
    }

    @Override
    public List<RolePermissionCenter> findByRolePid(Long rolePid) {
        return baseMapper.findByRolePid(rolePid);
    }
}
